package top.cptr.so.aliyundomainserver.controller;


import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import top.cptr.so.aliyundomainserver.aliyunSDKUtils.exception.AccessKeyIsNullException;
import top.cptr.so.aliyundomainserver.aliyunSDKUtils.exception.CreateClientException;
import top.cptr.so.aliyundomainserver.aliyunSDKUtils.exception.RequestInterfaceException;
import top.cptr.so.aliyundomainserver.pojo.R;

/**
 * 异常处理器
 */
@RestControllerAdvice
public class ExceptionAdvice {
    @ExceptionHandler(AccessKeyIsNullException.class)
    public R ExecAccessKeyIsNull(){
        R r = new R();
        r.setStatus(false);
        r.setMessage("token不存在");
        return r;
    }
    @ExceptionHandler(CreateClientException.class)
    public R ExecCreateClient(){
        R r = new R();
        r.setStatus(false);
        r.setMessage("创建连接错误");
        return  r;
    }
    @ExceptionHandler(RequestInterfaceException.class)
    public R ExecRequestInterface(RequestInterfaceException e){
        R r = new R();
        r.setStatus(false);
        r.setMessage(e.getMessage());
        return r;
    }
    @ExceptionHandler(Exception.class)
    public R otherException(){
        R r = new R();
        r.setStatus(false);
        r.setMessage("错误");
        return r;
    }
}
